<?php
/**
 * Created by Jayli.
 * User: Administrator
 * Date: 2018-03-07
 * Time: 14:46
 */

namespace App\Http\Controllers\Web\Member\Seller;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

class ShopCategoriesController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'seller/shopcategories'],
        'store' => ['post', 'seller/shopcategories'],
        'update' => ['put', 'seller/shopcategories/%d'],
        'destroy' => ['delete','seller/shopcategories/%d'],
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_web');
    }

    public function index()
    {

        //请求部分
        $ret = http_web($this->api_url['index'])->send();

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        return view('web.user.seller.shop_design_custom', $data);
    }


    public function store()
    {
        //参数部分
        $this->validate($this->request, [
            'name' => 'required|unique:shop_categories,name,NULL,id,shop_id,'.session('user_shop_id'),
        ],[
            'name.required'=>'请填写产品分类名称',
            'name.unique'=>'本店铺产品分类名称不可重复',
        ]);

        //请求部分
        $ret = http_web($this->api_url['store'])->send($this->request->all());
        return $ret;
    }

    public function update($id)
    {
        $this->validate($this->request, [
            'name' => 'required|unique:shop_categories,name,'.$id.',id,shop_id,'.session('user_shop_id'),
        ],[
            'name.required'=>'请填写产品分类名称',
            'name.unique'=>'本店铺产品分类名称不可重复',
        ]);
        //请求部分
        $ret = http_web($this->api_url['update'], [$id])->send($this->request->all());
        return $ret;
    }

    public function destroy($id)
    {

        //请求部分
        $ret = http_web($this->api_url['destroy'], [$id])->send();
        return $ret;

    }

}